package com.gitee.xmhzzz.rocketmq.spring.boot.quick.listener;


import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * @ClassName MqttBridgeRocketmqListener
 * @Description
 * @Author wzq
 * @Date 2024/1/22 16:51
 * @Version 1.0
 */
@Slf4j
@Service
@RocketMQMessageListener(topic = "spring-example-topic",
        consumerGroup = "example-listener",
        selectorExpression = "*")
public class ExampleListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        long time = System.currentTimeMillis();
        byte[] body = messageExt.getBody();
        String message = new String(body, StandardCharsets.UTF_8);
        log.info("mq 消息 start topic[{}] tag[{}] msgId[{}] time[{}] msg[{}] ", messageExt.getTopic(), messageExt.getTags(), messageExt.getMsgId(), time,message);
        //todo 业务逻辑
        log.info("mq 消息 end msgId[{}] time[{}]", messageExt.getMsgId(), System.currentTimeMillis() - time);
    }

}
